// Loesung_von_Aufgabe_2.2.5_2_Erwin_und_Hilde

// Erwin (E) und Hilde (H)

// Erwin
float xE0 = 100;
float xE;
float yE0 = 90;
float yE;
float vxE = 500; // Geschwindigkeit von Erwin in x-Richtung

// Hilde
float xH0 = 250;
float yH0 = 90;
float yH;

float g = 9810;
float h;
float t;

void setup()
{
  size(350, 550);
}

void draw()
{
  background(255);

  /* Eine möglichst hohe Bildwiederholungsrate wählen, 
   damit die Zeitschritte pro Durchlauf von void draw()
   sehr klein werden. */
  frameRate = 1000;
  t = t + 1/frameRate;

  yE = 0.5*g*t*t + yE0;
  xE = vxE*t + xE0;
  yH = 0.5*g*t*t + yH0;

  // "Stühle"
  fill(200);
  rect(0, 90, 100, 550);
  rect(250, 90, 100, 550);

  //  Hilde
  fill(255, 130, 130);
  ellipse(xH0, yH, 20, 20);

  // Erwin
  fill(130, 130, 255);
  ellipse(xE, yE, 20, 20);

  // Intervall "Erwin trift Hilde"
  if (yE <= yH+0.1 && yE >= yH-0.1  && xE <= xH0+0.1 && xE >= xH0-0.1)
  {
    h = 550 - yE;

    fill(0, 0, 255);
    textSize(24);
    text("h in mm = " +round(h), 100, 50);
    noLoop();
  }
}